trigger leadTask on Task (before insert) {
 
 ListViewIds__c LV = ListViewIds__c.getInstance();  
 
 ID localAdvertiserRecordTypeID = RecordTypeHelper.GetRecordTypeID('Task', 'Local Advertiser Task');      
 Id SfaNJQueueId = LV.SFA_OOR_New_Jersey_Sharkpool__c;           
 Id SfaSLCQueueId = LV.SFA_OOR_Salt_Lake_Sharkpool__c;
 
 List<Lead> lstLead=new List<Lead>();
 Set<Id> setTaskIds=new Set<Id>();
        
        for(Task t: Trigger.New){    
             
             if(t.whoid !=null){     
             try{          
                  system.debug('Lead Whoid' +t.whoid);           
                  string strOwnerId=(string)t.WhoId;            
                  if(strOwnerId.startsWith('00Q') && t.recordtypeid ==localAdvertiserRecordTypeID )       
                         { 
                         setTaskIds.add(t.WhoId);     
                         system.debug('Lead setEventIds ' +setTaskIds);
                         }
                  }catch(exception e2){
                  system.debug('eeeee'+e2);
                  }             
                }
                }
        lstLead=[select Id,ownerid,name from lead where Id in :setTaskIds];
        
        for(Task tk : Trigger.new){
            try{                 
              for(Lead ld : lstLead){              
                    if(tk.WhoId ==ld.Id){  
                    system.debug('AAAAAAA '+tk.whoid );         
                
                        if(ld.ownerid == SfaNJQueueId || ld.ownerid==SfaSLCQueueId){
                            system.debug('Inside Error');                                 
                            tk.addError('Owner of this Lead is Queue, Accept the lead to create any task');   
                            }
                   }
                }
            }catch(exception e1){               
            system.debug ('Lead exception '+e1);                  
            }
        }
}